package vaccine.appointment.system.vaccine.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import vaccine.appointment.system.common.annotation.AutoWrapResult;
import vaccine.appointment.system.common.annotation.RequireRole;
import vaccine.appointment.system.user.enums.IdentityInfoEnum;
import vaccine.appointment.system.vaccine.dataobject.Vaccine;
import vaccine.appointment.system.vaccine.service.VaccineService;
import vaccine.appointment.system.vaccine.vo.VaccineListVO;

/**
 * 疫苗控制器
 */
@AutoWrapResult
@RequestMapping("/vaccine")
@RestController
public class VaccineController {
    @Autowired
    private VaccineService vaccineService;

    /**
     * 增加疫苗
     * @param vaccine
     * @return
     */
    @RequestMapping("/add")
    public Boolean insert(Vaccine vaccine) {
        return vaccineService.insert(vaccine);
    }

    /**
     * 删除疫苗
     * @param id
     * @return
     */
    @RequestMapping("/del")
    public Boolean delete(Integer id) {
        return vaccineService.delete(id);
    }

    /**
     * 通过id查找疫苗
     * @param id
     * @return
     */
    @RequestMapping("/selectById")
    public Vaccine selectById(Integer id) {
        return vaccineService.selectById(id);
    }

    /**
     * 更新疫苗
     * @param vaccine
     * @return
     */
    @RequestMapping("/update")
    public Boolean update(Vaccine vaccine) {
        return vaccineService.update(vaccine);
    }

    /**
     * 查询疫苗列表
     * @param type 疫苗类型（可选）
     * @param pageNum 页码
     * @param pageSize 每页大小
     * @return 分页数据
     */
    @GetMapping("/list")
    @RequireRole({IdentityInfoEnum.NORMAL_USER, IdentityInfoEnum.HOSPITAL_ADMIN, IdentityInfoEnum.SUPER_ADMIN})
    public Page<VaccineListVO> getVaccineList(
            @RequestParam(required = false) Integer type,
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize) {
        return vaccineService.getVaccineList(type, pageNum, pageSize);
    }
}
